snap list | grep multipass
if [[ $? -eq 1 ]]
then
  sudo snap install multipass
fi
servers=(k3s worker1 worker2)
for s in ${servers[@]}
do
  multipass list | grep $s
  if [[ $? -eq 0 ]]
  then
    multipass delete $s
  fi
done
multipass purge
multipass list | grep -i k3s
if [[ $? -eq 1 ]]
then
  multipass launch --name k3s --cpus 2 --memory 8G --disk 10G
  multipass exec k3s -- sed -i '$aexport http_proxy=http://192.168.0.249:7890;\nexport http_proxy=https://192.168.0.249:7890;\nexport all_proxy=socks://192.168.0.249:7890;\n' /home/ubuntu/.bashrc
fi
multipass exec k3s -- bash -c "curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -"
TOKEN=$(multipass exec k3s sudo cat /var/lib/rancher/k3s/server/node-token)
MASTER_IP=$(multipass info k3s | grep IPv4 | awk '{print $2}')
for f in 1 2; do
  multipass list | grep -i worker$f
  if [[ $? -eq 1 ]]
  then
    multipass launch --name worker$f --cpus 2 --memory 8G --disk 10G
    multipass exec worker$f --  sed -i '$aexport http_proxy=http://192.168.0.249:7890;\nexport http_proxy=https://192.168.0.249:7890;\nexport all_proxy=socks://192.168.0.249:7890;\n' /home/ubuntu/.bashrc
  fi
  multipass exec worker$f -- bash -c "curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=\"https://$MASTER_IP:6443\" K3S_TOKEN=\"$TOKEN\" sh -"
done
